package xerr

var MapErrMsg map[int]string

func init() {
	MapErrMsg = make(map[int]string)
	MapErrMsg[SUCCESS] = "success"
	MapErrMsg[ERROR] = "error"
	MapErrMsg[UNKNOW_ERROR] = "未知错误"
	MapErrMsg[SERVER_COMMON_ERROR] = "服务器开小差啦,稍后再来试一试"
	MapErrMsg[PARAM_FORMAT_ERROR] = "参数格式错误"

	// JWT
	MapErrMsg[NOT_LOGIN] = "未登录或非法访问(权限不足)"
	MapErrMsg[TOKEN_EXPIRED] = "token is expired"
	MapErrMsg[TOKEN_NOT_VALID_YET] = "Token not active yet"
	MapErrMsg[TOKEN_MALFORMED] = "That's not even a token"
	MapErrMsg[TOKEN_INVALID] = "Couldn't handle this token"
	MapErrMsg[TOKEN_FAIL_CREATE] = "token 颁布失败"
	MapErrMsg[LOGIN_EXPIRETION] = "登录过期"

	// DB
	MapErrMsg[RECORD_DUPLICATER] = "记录已存在"
	MapErrMsg[RECORD_NOT_EXIT] = "记录不存在"

	// USER
	MapErrMsg[USER_NOT_EXIT] = "用户不存在"

	// POST
	MapErrMsg[POST_NOT_EXIT] = "帖子不存在"

}

func GetMsgByCode(code int) string {
	if msg, ok := MapErrMsg[code]; ok {
		return msg
	}
	return MapErrMsg[UNKNOW_ERROR]
}
